// 膳食管理 / 食材管理

import r from '@/utils/request';
import type { ListParams, ListResponseType, ResponseType } from '../types';

enum API {
    list = '/foods/list', //食材管理
    del = '/foods/delete/', //删除食材
    add = '/foods/add', //添加食材
    foodpricelist = '/foodprice/list/',//根据id获取食材价格
    foodpriceadd = '/foodprice/add',//添加食材价格
    foodpriceupdate = '/foodprice/update',//修改食材价格
    foodsget = '/foods/get/', //根据id获取食材
    update = '/foods/update',//修改食材
    deleteprice = '/foodprice/delete/',//删除食材价格
    delAll = '/foods/deleteAll'//批量删除食材
}

type GetfoodslistResType = ListResponseType<{
    id: number,
    companyId: number,
    name: string,
    linkMan: string,
    mobile: string,
    foodCounts: number
}>

type foodsgetResType = ResponseType<{
    id: number;
    companyId: number;
    name: string;
    unit: string;
    supplierId: number;
    wholePrice: any;
    sellPrice: any;
    purchasePrice: any;
    updateTime: any;
    supplierName: string;
}>

export interface foodsaddItem {
    name: string;
    unit: string;
    supplierId: number;
}

export interface foodsaddParams {
    id: number;
    name: string;
    unit: string;
    supplierId: number | undefined;
}

type foodsaddResType = ResponseType<{
    id: number;
    companyId: number;
    name: string;
    unit: string;
    supplierId: number;
    wholePrice: any;
    sellPrice: any;
    purchasePrice: any;
    updateTime: any;
    supplierName: any;
}>
type FoodsPriceListResType = ListResponseType<{
    id: number;
    foodId: number;
    wholePrice: number;
    sellPrice: number;
    purchasePrice: number;
    updateTime: string | null;
    addAccountId: number;
    addAccountName: any;
}>



export interface FoodsPriceAddParams {
    id: number;
    foodId: number;
    wholePrice: string;
    sellPrice: string;
    purchasePrice: string;
    updateTime: string;
}
type FoodsPriceAddResType = ResponseType<{
    id: number;
    foodId: number;
    wholePrice: number;
    sellPrice: number;
    purchasePrice: number;
    updateTime: string;
    addAccountId: number;
    addAccountName: any;
}>

export function foodslistAPI(params?: ListParams): Promise<GetfoodslistResType> {
    return r.get(API.list, params);
}
export function foodsgetAPI(id: number): Promise<foodsgetResType> {
    return r.get(API.foodsget + id);
}

export function DelfoodsAPI(id: number): Promise<ResponseType<null>> {
    return r.delete(API.del + id);
}
export function FoodsAddAPI(params: foodsaddParams): Promise<foodsaddResType> {
    return r.post(API.add, params);
}

export function FoodsPriceListAPI(params: ListParams, id: number): Promise<FoodsPriceListResType> {
    return r.get(API.foodpricelist + id, params);
}

export function FoodsPriceAddAPI(params: FoodsPriceAddParams): Promise<FoodsPriceAddResType> {
    return r.post(API.foodpriceadd, params);
}

export function FoodsUpdateAPI(params: foodsaddParams): Promise<foodsaddResType> {
    return r.put(API.update, params);
}

export function FoodsPriceUpdateAPI(params: FoodsPriceAddParams): Promise<FoodsPriceAddResType> {
    return r.put(API.foodpriceupdate, params);
}

export function DelFoodsPriceAPI(id: number): Promise<ResponseType<null>> {
    return r.delete(API.deleteprice  + id);
}
export function DelAllFoodsPriceAPI(id: number[]): Promise<ResponseType<null>> {
    return r.post(API.delAll, id);
}